//
//  FindHeaderV.m
//  ShandsMod
//
//  Created by zh s on 2023/3/22.
//  Copyright © 2023 zh_s. All rights reserved.
//

#import "FindHeaderV.h"

@interface FindHeaderV ()<UITextFieldDelegate>

@end

@implementation FindHeaderV

- (instancetype)init {
    if (self = [super init]) {
        [self addViews];
    }
    return self;
}

- (void)addViews {
    UITextField *inputTF = [[UITextField alloc] init];
    [self addSubview:inputTF];
    inputTF.placeholder = @"请输入您要搜索的内容~";
    inputTF.textColor = MAIN_BACKCOLOR;
    inputTF.font = FONT_NAME(FONT_Regular, 13);
    
    UIView *leftView = [[UIView alloc] init];
    leftView.frame = CGRectMake(0, 0, 20, 22);
    inputTF.leftView = leftView;
    inputTF.leftViewMode = UITextFieldViewModeAlways;
    [inputTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(STATUS_BAR_HEIGHT + 15);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 40 -40, 38));
    }];

    inputTF.tag = 100;
    
    inputTF.delegate = self;
    inputTF.keyboardType = UIKeyboardTypeWebSearch;
    inputTF.backgroundColor = BASE_BACKCOLOR;
    GWRadius(inputTF, 19);
    
    UIButton *searchBtn = [BaseViewFactory buttonWithFrame:CGRectZero font:FONT_NAME(FONT_Semibold, 12) title:@"搜索" titleColor:UIColor.whiteColor backColor:MAIN_ACTIVE_COLOR];
    [self addSubview:searchBtn];
    [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).mas_offset(-20);
        make.centerY.mas_equalTo(inputTF.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(70, 38));
    }];
    [searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
    GWRadius(searchBtn, 19);
    
    
    

}

- (void)searchClick {
    [self endEditing:YES];
    UITextField *tf = [self viewWithTag:100];
    self.findSearchViewBlock(tf.text);
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self endEditing:YES];
    UITextField *tf = [self viewWithTag:100];
    self.findSearchViewBlock(tf.text);
    return YES;
}

@end
